package replaceWords;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ReplaceWordXML {

	final String tagStringForWords = "XX";
	final long errorSleep = 2000;

	String replaceWord(String wordSource) throws Exception {
		String wordReplace = wordSource;

		for (int i = 0; i < wordsList.size(); i++) {
			String word = wordsList.get(i);
			String word2 = newonesList.get(i);
			String ids = word + "\\|";
			String ids2 = word2 + "#";
			Pattern p = Pattern.compile(ids);
			Matcher m = p.matcher(wordReplace);
			wordReplace = m.replaceAll(ids2);
		}

		// 正常的运行替换完成了，break跳出死循环

		return (wordReplace);

	}

	List<String> wordsList = new ArrayList();
	public void setWordsList(List<String> wordsList) {
		this.wordsList = wordsList;
	}

	public void setNewonesList(List<String> newonesList) {
		this.newonesList = newonesList;
	}

	List<String> newonesList = new ArrayList();

}
